I built two parts of my app a bit disjointed:
- my physics component, which controls all SceneReconstruction, HandTracking, and WorldTracking.
- my spatial GroupActivities component that allows you to see personas of those that join the activity.
My problem: When trying to use any DataProvider in a spatial experience, I get the ARKit Session Event: dataProviderStateChanged, which disables all of my providers.
My question: Has anyone successfully been able to find a workaround for this? I think it would be amazing to have one user be able to be the "host" for the activity and the scene reconstruction provider still continue to run for them.
I just figured this out today! For those that are potentially having a similar problem,
Have a class similar to -
@MainActor
class MyClass: ObservableObject, @unchecked Sendable { ... }
Make sure this class has all instances of DataProvider
s you need and also has an instance of ARKitSession
.
Then, in your main file or wherever you declare your App
's SwiftUI.Scene
, have something similar to this outside of the App
block:
@MainActor
enum MyClassContainer {
private(set) static var myClass = MyClass()
}
and inside of your SwiftUI.Scene
block -
ImmersiveSpace(id: "myId") {
MyImmersionView(myClass: MyClassContainer.myClass)
}
.immersionStyle(selection: $immersiveController.currentStyle, in: .mixed)
then, make sure you actually run the ARKitSession
inside of your immersive space inside of a .task{}
method chain off the end of the RealityView
block!
Hope this helps :)